#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "HttpProtocolParse.h"
#include "Engine.h"
#include "EchoHandler.h"

using namespace HttpFrame::Loger;


namespace HttpFrame
{

int CEchoHandler::Init(CIniFile &ini
    	                        ,COperationEngine *pEngine)
{
     return 0;
}

     	
int CEchoHandler::ProcessPack(COperationEngine *pEngine,
    	                                    CHttpProtocolParse &reqParse,
     	                                    CHttpProtocolParse &rspParse)
{
    CmdEchoRequest *pReq = (CmdEchoRequest*)reqParse.GetBody();
    if(pReq==NULL)
    {
        pEngine->Logger()->LOG_P(HttpFrame::Loger::LOG_ERROR, "CEchoHandler::ProcessPack, Get Request Body false: %s\n", (char*)reqParse.GetData());
        return -1;
    }
    
    Ntoh(pReq);
    
    pEngine->Logger()->LOG_P(HttpFrame::Loger::LOG_ERROR, "CEchoHandler::ProcessPack, Request data: %s\n", pReq->szData);

    CmdEchoResponse rsp;
    memset(&rsp,0,sizeof(rsp));

    snprintf(rsp.szData,sizeof(rsp.szData)-1,"%s",pReq->szData);
    rspParse.AddExtPara("X_ABSTRACT",rsp.szData);

    pEngine->Logger()->LOG_P(HttpFrame::Loger::LOG_ERROR, "CEchoHandler::ProcessPack, Response data: %s\n", rsp.szData);

    Hton(&rsp);

    rspParse.MakeRespone(0,"ok","10","0",&rsp,sizeof(rsp));
    
    return 0;
}


}

